<template>
  <div class="nav-header">
    <div class="logo">
      <img class="img" src="~@/assets/img/logo.svg" alt="logo" />
      <span class="title">Vue3+TS</span>
    </div>
    <div class="avatar">
      <el-avatar :src="avatarUrl" />
      <div @click="loginOut">退出登录</div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'

import cache from '@/utils/localCache'
import { useRouter } from 'vue-router'

export default defineComponent({
  name: 'NavHeader',
  setup() {
    const avatarUrl = ref('https://img1.baidu.com/it/u=2115417574,2013087923&fm=253&fmt=auto&app=138&f=JPEG?w=796&h=418')

    const router = useRouter()

    const loginOut = () => {
      cache.clearCache()

      router.replace('/login')
    }

    return {
      avatarUrl,
      loginOut
    }
  }
})
</script>

<style scoped lang="less">
.nav-header {
  width: 100%;
  height: 48px !important;
  border-bottom: 1px solid #ccc;

  display: flex;
  justify-content: space-between;
  align-items: center;

  .logo {
    display: flex;
    align-items: center;

    img {
      width: 25px;
      height: 25px;
      margin: 0 10px;
    }

    span {
      font-size: 16px;
      font-weight: 700;
      color: #000;
    }
  }

  .avatar {
    height: 48px;
    display: flex;
    align-items: center;
    div {
      margin: 0 5px;
      cursor: pointer;
      &:hover {
        color: #409EFF;
      }
    }
  }
}
</style>
